from __future__ import annotations

from datetime import datetime

from pydantic import EmailStr, Field

from app.schemas.common import APIModel


class RegisterRequest(APIModel):
  email: EmailStr
  username: str = Field(min_length=3, max_length=32)
  password: str = Field(min_length=8, max_length=64)


class LoginRequest(APIModel):
  email: EmailStr | None = None
  username: str | None = None
  password: str = Field(min_length=8, max_length=64)


class Token(APIModel):
  access_token: str
  refresh_token: str
  token_type: str = "bearer"
  expires_in: int
  refresh_expires_in: int


class TokenPayload(APIModel):
  sub: str
  exp: int


class RefreshRequest(APIModel):
  refresh_token: str


class SessionResponse(APIModel):
  session_id: int
  expires_at: datetime


class ResendVerificationRequest(APIModel):
  email: EmailStr


class VerifyEmailRequest(APIModel):
  email: EmailStr
  code: str = Field(min_length=4, max_length=8)


class ForgotPasswordRequest(APIModel):
  email: EmailStr


class ResetPasswordRequest(APIModel):
  token: str = Field(min_length=16, max_length=200)
  new_password: str = Field(min_length=8, max_length=64)
